package com.Action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.Bean.wdhtcustomerModel;
import com.Bean.wdhtroomModel;
import com.Bean.wdreceptionrecordModel;
import com.Bean.wdsalechanceModel;
import com.Service.*;
@Controller
public class wdSaleManagerAction {
@Autowired
 private wdSaleManagerService wdSaleManagerService;
@Autowired
private wdhtroommodelService wdhtroommodelService;
@Autowired
private wdreceptionrecordService wdreceptionrecordService;
//查询所有值放在table表格里
@RequestMapping("/selectsale.do")
public String selectAll(Model model,wdsalechanceModel sbean) {
	 sbean.setDeleteState("1"); 
	
	 System.out.println("1111");
	 if("".equals(sbean.getCustomerName())){
			sbean.setCustomerName(null);
		}
	 if("".equals(sbean.getSaleChanceName())){
			sbean.setSaleChanceName(null);
		}
	 if("".equals(sbean.getNumber())){
			sbean.setNumber(null);
		}
	 
	 System.out.println("-============"+sbean.getSaleChanceName());
   List<wdsalechanceModel> list  = wdSaleManagerService.getList(sbean);
   System.out.println("---------------"+list.size());
   for(wdsalechanceModel a:list){
	   System.out.println(a.getTel());
   }
   model.addAttribute("list", list);
	System.out.println(list);
	return "SaleManager";
}
//查询客户信息放在表单里
@RequestMapping("/selectSaleManage.do")
public @ResponseBody Map<String, Object> toAjaxCustomer(wdreceptionrecordModel wbean){
	System.out.println("================"+wbean.getCustomerId());
	String cid = wbean.getCustomerId();
	wdreceptionrecordModel wRRbean =  wdreceptionrecordService.selectSaleCustomer(cid);
   System.out.println(""+wRRbean.getUserName());
   
	Map<String, Object> comMap = new HashMap<String, Object>();
	comMap.put("customer", wRRbean);
	return comMap;
}
//查询房间表把数据放在表单里
@RequestMapping("selectroom.do")
public @ResponseBody Map<String, Object> toAjax(wdhtroomModel rbean){
	String rid = rbean.getRoomId();
	wdhtroomModel rmbean = wdhtroommodelService.selectByPrimaryKey(rid);
	  Map<String, Object> comMap = new HashMap<String, Object>();
	  comMap.put("room", rmbean);
	  return comMap;
	}
//添加客户接待记录
@RequestMapping("addsaleManager.do")
public String addsaleManager(wdsalechanceModel sbean) throws ParseException{
	
	String n = "1";
	sbean.setDeleteState(n);
	  SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
	   System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
	   Date date=new Date(); 
	sbean.setAddtime(date);
	int i = wdSaleManagerService.addsalemanager(sbean);
	System.out.println("添加成功"+i);
	return "redirect:selectsale.do";
}
//根据id查询数据放在表单里
@RequestMapping("/selectsaleupdate.do")
public String selectsaleupdate(Model model,wdsalechanceModel sbean){
	
	String saleChanceId = sbean.getSaleChanceId();
	wdsalechanceModel scbean = wdSaleManagerService.selectsale(saleChanceId);
	model.addAttribute("saleupdate", scbean);
	 return "updatesalemanager";
}
//修改数据
@RequestMapping("/updatesale.do")
public String updatesale(wdsalechanceModel scbean){
	int i = wdSaleManagerService.updatesale(scbean);
	return "redirect:selectsale.do";
}
@RequestMapping("/deletesale.do")
public String deletesalemanager(wdsalechanceModel scbean){
	scbean.setDeleteState("0");
	int i = wdSaleManagerService.updatesale(scbean);
	
	return "redirect:selectsale.do";
}
}
